function G = fddirect1d(N)
% Solve the Green's function of -u'' + (1+sin(x)) u  on [0,1] with
% periodic boundary condition using finite difference.
h = 1 / N;
xmesh = (0:N-1)'*h;
e = ones(N,1);
V = 1+sin(2*pi*xmesh);
A = 1/h^2 * spdiags([-e 2*e -e], ...
  -1:1, N, N) + spdiags(V, 0, N, N);
A(1,N) = -1/h^2;
A(N,1) = -1/h^2;
f = eye(N);
ux = A \ f;
G = ux;
